package cn.myschool;

import cn.myschool.dao.StudentMapper;
import cn.myschool.entity.Student;
import cn.myschool.entity.StudentExample;
import myschool.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.defaults.DefaultSqlSession;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestQuery {
    public static void main(String[] args) throws ParseException {
        //qq,sname,wechat,telephone,enterdate
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        Date start=df.parse("2016-12-1");
        Date end=df.parse("2019-12-1");
        SqlSession s= MyBatisUtil.get();
        DefaultSqlSession sss=null;
        StudentMapper mapper=s.getMapper(StudentMapper.class);
        
        //>System.out.println(mapper.getClass().getName());
        //动态代理

        StudentExample stu=new StudentExample();
        stu.setOrderByClause("stuno desc");
        //限制条件
        StudentExample.Criteria criteria = stu.createCriteria();
        criteria.andSnameLike("%李%");
        criteria.andTelephoneLike("%1%");
//        criteria.andQqLike("%5%");
        criteria.andEnterdateGreaterThanOrEqualTo(start);
        criteria.andEnterdateLessThanOrEqualTo(end);
        //criteria.andWechatLike("%4%");
        List<Student> students = mapper.selectByExample(stu);
        students.forEach(System.out::println);
        MyBatisUtil.close(s);
    }
}
